package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.protocol.Common.PBUserCaveInfo;
import com.motu.monstercity.server.game.userdata.*;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;

import java.util.ArrayList;
import java.util.List;

public class CaveUserData extends CaveBaseData {
    public static UserCaveInfo getUserCaveInfo(long userId) {
        return (UserCaveInfo) EntityManager.getUniqueEntity(UserCaveInfo.class, userId);
    }

    public static UserCaveLocation getUserCaveLocation(long userId) {
        return (UserCaveLocation) EntityManager.getUniqueEntity(UserCaveLocation.class, userId);
    }

    public static UserCaveRecord getUserCaveRecorde(long userId, long dbid) {
        return (UserCaveRecord) EntityManager.getEntity(UserCaveRecord.class, userId, dbid);
    }

    public static List<UserCaveRecord> getUserCaveRecordList(long userId) {
        List<UserCaveRecord> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserCaveRecord.class, userId)) {
            UserCaveRecord entity = (UserCaveRecord) model;
            list.add(entity);
        }
        return list;
    }

    public static ServerCaveLocation getServerCaveLocation(int serverId, int caveKey) {
        return (ServerCaveLocation) EntityManager.getEntity(ServerCaveLocation.class, serverId, caveKey);
    }

    public static List<ServerCaveLocation> getServerCaveLocationList(int serverId) {
        List<ServerCaveLocation> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(ServerCaveLocation.class, serverId)) {
            ServerCaveLocation entity = (ServerCaveLocation) model;
            list.add(entity);
        }
        return list;
    }
}
